<%-- 
    Document   : search
    Created on : Jan 14, 2014, 12:53:41 AM
    Author     : lenovo
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.*" %>
<%@page import="model.Search" %>
<%@page import="database.DBClass"%>
<%@page import="validation.ValidateForm"%>
<%@page import ="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <%
            Search sear = new Search();
            DBClass dbobject = new DBClass();
            String inputsearch = (String) request.getAttribute("Search");
            String range1 = (String) request.getAttribute("Range1");
            String range2 = (String) request.getAttribute("Range2");
//            int range1 = Integer.parseInt(rangea);
//            int range2 = Integer.parseInt(rangeb);
        %>
        <title>E-Stonion</title>

        <style type="text/css">
            body {
                background-color:black;
                background-image:url(images/4.jpg); 
            }
        </style>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="<%request.getContextPath();%>/E-Stonion/css/metro-bootstrap.css" rel="stylesheet"> 
        <link href="<%request.getContextPath();%>/E-Stonion/css/metro-bootstrap-responsive.css" rel="stylesheet">
        <link href="<%request.getContextPath();%>/E-Stonion/js/prettify/prettify.css" rel="stylesheet">

        <script src="<%request.getContextPath();%>/E-Stonion/js/jquery/jquery.min.js"></script>
        <script src="<%request.getContextPath();%>/E-Stonion/js/jquery/jquery.widget.min.js"></script>
        <script src="<%request.getContextPath();%>/E-Stonion/js/jquery/jquery.mousewheel.js"></script>
        <script src="<%request.getContextPath();%>/E-Stonion/js/prettify/prettify.js"></script>
        <!-- Metro UI CSS JavaScript plugins -->
        <script src="<%request.getContextPath();%>/E-Stonion/js/load-metro.js"></script>

        <!-- Local JavaScript -->
        <script src="<%request.getContextPath();%>/E-Stonion/js/docs.js"></script>
        <script src="<%request.getContextPath();%>/E-Stonion/js/github.info.js"></script>

        <script src="<%request.getContextPath();%>/E-Stonion/js/metro/metro-*.js"></script>
        <title>E-Stonion Home</title>

    </head>
    <body class="metro">
        <nav class="navigation-bar">
            <nav class="navigation-bar-content">
                <a class="element" href="/E-Stonion/home.jsp">
                    <span class="icon-grid-view"></span>
                    E-Stonion </a>
                <span class="element-divider"></span>
                <a class="element" href="home.jsp">Home</a>
                <a class="element" href="produk.jsp">Produk</a>
                <a class="element" href="koperasi.jsp">Koperasi</a>
                <a class="element" href="aboutus.jsp">About Us</a>
                <span class="element-divider"></span>
                <div class="element input-element place-right">
                    <form method="post" action="<%request.getContextPath();%>/E-Stonion/SearchServlet">
                        <div class="input-control text">
                            <input type="text" name="inputsearch" value="" placeholder="Search...">
                            <button class="btn-search" name="action" value="SearchAll"></button>
                        </div>
                    </form>
                </div>
                <span class="element-divider place-right"></span>
            </nav>
        </nav>
        <%
            if (request.getAttribute("searchtype") == null) {

        %>
    <center>
        No Search
    </center>
        <%        } else if (request.getAttribute("searchtype").equals("all")) {

        %>
        <table width="100%"border="1" class="table table-striped">
            <tr>
                <th>Nama Produk</th>
                <th>Harga Produk</th>
                <th>Jenis Produk</th>
                <th>Nama Koperasi</th>
            </tr>
            <%
                List list = dbobject.SearchAll(inputsearch);
                //                request.setAttribute("list", list);
                //            List list = (List) request.getAttribute("list");
                if (list != null) {
                    for (int i = 0; i < list.size(); i++) {
                        Search usear = (Search) list.get(i);
            %>
            <tr>
                <td><%=usear.getnamaproduk()%></td>
                <td>Rp <%=usear.gethargaproduk()%></td>
                <td><%=usear.getjenisproduk()%></td>
                <td><%=usear.getnamakoperasi()%></td>
            </tr>
            <%
                    }
                }
            %>
        </table>
        <%
            } else if (request.getAttribute("searchtype").equals("produk")) {
        %>
         <table width="100%"border="1" class="table table-striped">
            <tr>
                <th>Nama Produk</th>
                <th>Harga Produk</th>
                <th>Jenis Produk</th
            </tr>
            <% if (request.getAttribute("produktype") == null) {

            %>
            <tr>
                <td></td>
                <td></td>
                <td></td>
            </tr>
            <%
            } else if (request.getAttribute("produktype").equals("jenis")) {
                List list = dbobject.SearchJenis(inputsearch);
                request.setAttribute("list", list);
                List list1 = (List) request.getAttribute("list");
                if (list1 != null) {
                    for (int i = 0; i < list1.size(); i++) {
                        Search usear = (Search) list1.get(i);
            %>
            <tr>
                <td><%=usear.getnamaproduk()%></td>
                <td>Rp <%=usear.gethargaproduk()%></td>
                <td><%=usear.getjenisproduk()%></td>
            </tr>
            <%
                    }
                }
            } else {
                List list2 = dbobject.SearchHarga(range1,range2);
                request.setAttribute("list", list2);
                List list3 = (List) request.getAttribute("list");
                if (list3 != null) {
                    for (int i = 0; i < list3.size(); i++) {
                        Search usear = (Search) list3.get(i);

            %>
            <tr>
                <td><%=usear.getnamaproduk()%></td>
                <td>Rp <%=usear.gethargaproduk()%></td>
                <td><%=usear.getjenisproduk()%></td>
            </tr>
            <%
                        }
                    }
                }
            %>
        </table>
        <%
            }
            else if (request.getAttribute("searchtype").equals("kota")) {
        %>
        <table width="100%"border="1" class="table table-striped">
            <tr>
                <th>Nama Koperasi</th>
                <th>Alamat Koperasi</th>
                <th>No.telp Koperasi</th>
                <th>Kota Koperasi</th>
            </tr>
            <%
                List list = dbobject.SearchKota(inputsearch);
                //                request.setAttribute("list", list);
                //            List list = (List) request.getAttribute("list");
                if (list != null) {
                    for (int i = 0; i < list.size(); i++) {
                        Search usear = (Search) list.get(i);
            %>
            <tr>
                <td><%=usear.getnamakoperasi()%></td>
                <td><%=usear.getalamatkoperasi()%></td>
                <td><%=usear.getnotelpkoperasi()%></td>
                <td><%=usear.getKota()%></td>
            </tr>
            <%
                    }
                }
            %>
        </table>
        <%
            }
        %>
    </body>
</html>
